package com.woniu.zsd.shopping.controller;


import cn.hutool.core.bean.BeanUtil;
import com.woniu.zsd.common.util.Result;
import com.woniu.zsd.common.web.PageInfo;
import com.woniu.zsd.shopping.form.QueryProductTypeFrom;
import com.woniu.zsd.shopping.param.QueryProductTypeParam;
import com.woniu.zsd.shopping.service.ProductTypeService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author zhangtao
 * @since 2025年02月18日
 */
@RestController
@RequestMapping("/productType")
@Api(tags = "商品类型管理类接口")
public class ProductTypeController {

    @Resource
    private ProductTypeService productTypeService;

    //新增商品类型
    @PostMapping("/addProductType")
    @ApiOperation("添加商品类型")
    public Result addProductType(String productTypeName)throws Exception{
        productTypeService.addProductType(productTypeName);
       return Result.success("添加商品类型成功");
    }

    //删除商品类型
    @PostMapping("/deleteProductType")
    @ApiOperation("删除商品类型")
    public Result deleteProductType(Integer productTypeId)throws Exception{
        productTypeService.deleteProductType(productTypeId);
        return Result.success("删除商品类型成功");
    }

    //查询商品类型
    @GetMapping("/queryProductType")
    @ApiOperation("查询商品类型")
    public Result queryProductType(QueryProductTypeFrom from)throws Exception{
        PageInfo pageInfo = productTypeService.queryProductType(BeanUtil.toBean(from, QueryProductTypeParam.class));
        return Result.success("查询商品类型成功",pageInfo);
    }

}

